package com.young.ums.model;


import java.util.Date;

/**
 * JWT对象
 * @author imrookie
 * @date 2018/9/16
 */
public class SsoJWT {

    private Header header;//头部
    private Payload payload;//荷载
    private String signature;//签名

    /**
     * 创建jwt实例
     * @return
     */
    public static SsoJWT newInstance(){
        SsoJWT jwt = new SsoJWT();
        jwt.setHeader(new Header());
        jwt.setPayload(new Payload());
        return jwt;
    }

    /**
     * 创建jwt实例
     * @param header
     * @param payload
     * @param signature
     * @return
     */
    public static SsoJWT newInstance(Header header, Payload payload, String signature){
        SsoJWT jwt = new SsoJWT();
        jwt.setHeader(header);
        jwt.setPayload(payload);
        jwt.setSignature(signature);
        return jwt;
    }

    private SsoJWT(){
        super();
    }

    //jwt头部信息
    public static class Header{
        private String typ;//类型
        private String alg;//签名算法

        public String getTyp() {
            return typ;
        }

        public void setTyp(String typ) {
            this.typ = typ;
        }

        public String getAlg() {
            return alg;
        }

        public void setAlg(String alg) {
            this.alg = alg;
        }
    }

    //jwt荷载
    public static class Payload{
        private String iss;//签发者
        private String sub;//面向的用户
        private String aud;//接收方
        private Date iat;//签发时间
        private Date exp;//过期时间
        private String userId;//用户id
        private String uuid;//唯一编码,整个jwt串太长,用该唯一编号来代替jwt做存储/查询等操作

        public String getIss() {
            return iss;
        }

        public void setIss(String iss) {
            this.iss = iss;
        }

        public String getSub() {
            return sub;
        }

        public void setSub(String sub) {
            this.sub = sub;
        }

        public String getAud() {
            return aud;
        }

        public void setAud(String aud) {
            this.aud = aud;
        }

        public Date getExp() {
            return exp;
        }

        public void setExp(Date exp) {
            this.exp = exp;
        }

        public Date getIat() {
            return iat;
        }

        public void setIat(Date iat) {
            this.iat = iat;
        }

        public String getUserId() {
            return userId;
        }

        public void setUserId(String userId) {
            this.userId = userId;
        }

        public String getUuid() {
            return uuid;
        }

        public void setUuid(String uuid) {
            this.uuid = uuid;
        }
    }

    public Header getHeader() {
        return header;
    }

    public void setHeader(Header header) {
        this.header = header;
    }

    public Payload getPayload() {
        return payload;
    }

    public void setPayload(Payload payload) {
        this.payload = payload;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }
}
